﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using System.IO;

public partial class BasicBase_ViewFile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AttachmentInfo atta = Attachment.GetAttachment(new Guid(Request.QueryString["FileID"]));
            FileStream fs = new FileStream(Server.MapPath("../"+atta.FilePath), FileMode.Open, FileAccess.Read);
            long fileSize = fs.Length;
            byte[] fileBuffer = new byte[fileSize];
            fs.Read(fileBuffer, 0, (int)fileSize);
            fs.Dispose();
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = atta.FileType;
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(atta.OraginalName) + "." + atta.FileExtension);
            Response.BinaryWrite(fileBuffer);
            Response.Flush();
            Response.End();
        }
    }
}
